/**
 * Created by fupeng on 17/3/6.
 */
var dao = require('../dao/MemberDao');

module.exports = {
    selectByOpenID: function (openid,callback) {
        var member = [];
        dao.selectByopenid(openid, function (data) {
            if (data.isSuccess) {
                if (data.rows.length > 0) {
                    data.rows.forEach(function (val) {
                        member.push({
                            openid:val.open_id,
                            city:val.city,
                            province:val.province,
                            country:val.country,
                            privilege:val.privilege,
                            member_id:val.member_id,
                            phone_number: val.phone_number,
                            sex:val.sex,
                            nickname:val.nickname,
                            headimgurl:val.headimgurl
                        });
                    });
                }
                callback(member);
            } else {
                callback( null);
            }
        })
    },
    addMember:function(userInfo,callback){
        dao.addMember(userInfo,callback);
    },
    selectByPhone: function (phone,callback) {
        var member = [];
        dao.selectByPhone(phone, function (data) {
            if (data.isSuccess) {
                if (data.rows) {
                    data.rows.forEach(function (val) {
                        member.push({
                            member_id:val.member_id,
                            openid: val.openid,
                            phone_number: val.phone_number,
                            sex:val.sex,
                            nickname:val.nickname,
                            headimgurl:val.headimgurl
                        });
                    });
                }
                console.log(member);
                callback(member);
            } else {
                callback( null);
            }
        })
    },
    userLogin:function (phone,calback){
        dao.userLog();
    }
}